package com.yz.group1.group_1.mapper;

import com.yz.group1.group_1.entity.UserBook;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

public interface UserBookMapper {
    @Insert("INSERT INTO user_book(patient_id, department_id, doctor_id, book_date, time_slot, status) " +
            "VALUES(#{patientId}, #{departmentId}, #{doctorId}, #{bookDate}, #{timeSlot}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserBook userBook);

    @Update("UPDATE user_book SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);

    @Select("SELECT * FROM user_book WHERE id = #{id}")
    UserBook selectById(Long id);

    @Select("SELECT * FROM user_book WHERE patient_id = #{patientId} ORDER BY book_date DESC")
    List<UserBook> selectByPatientId(Long patientId);

    @Select("SELECT * FROM user_book WHERE doctor_id = #{doctorId} AND book_date = #{bookDate} ORDER BY time_slot")
    List<UserBook> selectByDoctorAndDate(@Param("doctorId") Long doctorId, @Param("bookDate") Date bookDate);
}